#ifndef _L_COLLISION_RESULT_120130_H
#define _L_COLLISION_RESULT_120130_H

#include <ltypes.h>
#include <lmacros.h>
#include <ltriMesh.h>
#include <ldisjointSet.h>
#include <lirregularTable.h>

#include <set>
#include <map>

LLIB_BEGIN
namespace collision {

/* The collector and processor of collision result */
class CollisionResult {
public:
    /* The default constructor */
    CollisionResult() : _collisionGroup(NULL) {}

    /* The destructor */
    ~CollisionResult() { delete _collisionGroup; }

    /* Reset result */
    inline void Reset() { _faceMap.clear(); _pairSet.clear(); delete _collisionGroup; _collisionGroup = NULL; }

    /* Add a collision pair into set */
    void AddPair(geom::MeshFace& first, geom::MeshFace& second);

    /* Collect pair into groups */
    void Collect();

    /* Get the group number */
    inline Int32 size() const { BOOST_ASSERT(_collisionGroup != NULL); return _collisionGroup->size(); }

    /* overload operator [] */
    inline util::IrregularTableRow<geom::MeshFace> operator [] (Int32 index) { return (*_collisionGroup)[index]; }

private:
    /* The face index to local index mapper */
    std::map<geom::MeshFace,Int32> _faceMap; // face id -> local id

    /* The collision pair set */
    std::set< std::pair<geom::MeshFace,geom::MeshFace> > _pairSet;

    /* The collision groups */
    util::IrregularTable<geom::MeshFace>* _collisionGroup;

};


}
LLIB_END

#endif
